﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using LightCAD.MathLib;

namespace LightCAD.MathLib
{
    public class Circle2d : Curve2d
    {
        [JsonInclude]
        public Vector2 Center;
        public double Radius { get; set; }
        public override bool IsClosed { get => base.IsClosed;}
        public Circle2d() 
        {
            this.Center = null;
            this.Type = Curve2dType.Circle2d;
            this.IsClosed = true;
        }
        public override void Copy(Curve2d src)
        {
            var cir = src as Circle2d;
            this.Center= cir.Center.Clone();
            this.Radius = cir.Radius;
            this.Name = cir.Name;
        }
        public override Curve2d Clone()
        {
            var newObj = new Line2d();
            newObj.Copy(this);
            return newObj;
        }

        public override Curve2d Translate(Vector2 offset)
        {
            this.Center.Add(offset);
            return this;
        }

        public override Curve2d RotateAround(Vector2 basePoint, double angle)
        {
            this.Center.RotateAround(basePoint, angle);
            return this;
        }

        public override Curve2d Mirror(Vector2 axisStart, Vector2 axisDir)
        {
            this.Center.Mirror(axisStart,axisDir);
            return this;
        }
        public override Vector2[] GetPoints(int div = 5, double scaleInFuture = 1)
        {
            if (div <= 0)
            {
                div = (int)Math.Ceiling(this.Radius * scaleInFuture );
                if (div < 5)
                    div = 5;
            }
            var result = new Vector2[div + 1];
            for (int i = 0; i <= div; i++)
            {
                var delta = (double)i / div;
                result[i] = Ellipse2d.getEllipsePoint(this.Center, this.Radius, this.Radius, 0,Utils.TwoPI , 0, this.isClosed, delta);
            }
            return result;
        }
    }
}
